//
//  DrawerManager.m
//  QuickCare
//
//  Created by lidabiao on 16/7/13.
//  Copyright © 2016年 lidabiao. All rights reserved.
//

#import "DrawerManager.h"

@interface DrawerManager ()

@end

@implementation DrawerManager

+(instancetype)shareManager
{
    static DrawerManager *manager;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manager = [[DrawerManager alloc] init];
        
    });
    
    return manager;
}

-(void)setUpRootViewControllerWithCenterViewController:(MainViewController *)centerViewController LeftViewController:(LeftViewController *)leftViewController Completion:(void(^)(MMDrawerController *))completion
{
    _drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerViewController leftDrawerViewController:leftViewController];
    
    _leftVC = leftViewController;
    
    _centerVC = centerViewController;
    
    [_drawerController setShowsShadow:YES];
    // 左边拉开的最大宽度
    _drawerController.maximumLeftDrawerWidth = [UIScreen mainScreen].bounds.size.width * 3 / 4;
    
    [_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    
    [_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    
    [_drawerController setModalInPopover:YES];
    
    completion(_drawerController);
}

-(void)disableLeftDrawer
{
    [_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
        
        [_drawerController setLeftDrawerViewController:nil];
        
    }];
}

-(void)enableLeftDrawerAndOpenLeftDrawer
{
    [_drawerController setLeftDrawerViewController:_leftVC];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
    {
        [_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:^(BOOL finished)
         {
             [_drawerController setCenterViewController:_centerVC];
         }];
    });
    
}

-(void)presentViewController:(UIViewController *)viewController
{
    [_drawerController setCenterViewController:viewController withCloseAnimation:YES completion:nil];
}

@end
